﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using EQ1.Elements;
using EQ1.Objects;

namespace EQ1.Elements {
  public class ScreenPiece : UIClass , IUIElement<ScreenPiece> {
    public ScreenPiece ( UIDocument doc , string name )
      : base( doc , name ) {
      this.Font = 3;
      this.RelativePosition = true;
      this.AutoStretch = false;
      this.AutoStretchVertical = false;
      this.AutoStretchHorizontal = false;
      this.TopAnchorToTop = true;
      this.LeftAnchorToLeft = true;
      this.BottomAnchorToTop = true;
      this.RightAnchorToLeft = true;
      this.TopAnchorOffset = 0;
      this.BottomAnchorOffset = 0;
      this.LeftAnchorOffset = 0;
      this.RightAnchorOffset = 0;
      this.MinVSize = 0;
      this.MinHSize = 0;
      this.MaxVSize = 0;
      this.MaxHSize = 0;
      this.UseInLayoutHorizontal = true;
      this.UseInLayoutVertical = true;

    }
    public ScreenPiece ( UIDocument doc )
      : this( doc , "ScreenPiece" ) {
    }

    #region IUIElement<ScreenPiece> Members

    public void Validate ( ScreenPiece val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        ScreenPiece el = new ScreenPiece( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    public void Copy ( ScreenPiece val ) {
      base.Copy( val );

      this.Font = val.Font;
      this.RelativePosition = val.RelativePosition;
      this.AutoStretch = val.AutoStretch;
      this.AutoStretchVertical = val.AutoStretchVertical;
      this.AutoStretchHorizontal = val.AutoStretchHorizontal;
      this.TopAnchorToTop = val.TopAnchorToTop;
      this.LeftAnchorToLeft = val.LeftAnchorToLeft;
      this.BottomAnchorToTop = val.BottomAnchorToTop;
      this.RightAnchorToLeft = val.RightAnchorToLeft;
      this.TopAnchorOffset = val.TopAnchorOffset;
      this.BottomAnchorOffset = val.BottomAnchorOffset;
      this.LeftAnchorOffset = val.LeftAnchorOffset;
      this.RightAnchorOffset = val.RightAnchorOffset;
      this.MinVSize = val.MinVSize;
      this.MinHSize = val.MinHSize;
      this.MaxVSize = val.MaxVSize;
      this.MaxHSize = val.MaxHSize;
      this.UseInLayoutHorizontal = val.UseInLayoutHorizontal;
      this.UseInLayoutVertical = val.UseInLayoutVertical;

      if( !string.IsNullOrEmpty( val.ScreenID ) )
        this.ScreenID = val.ScreenID;
      if( this.Location != null )
        this.Location = val.Location;
      if( this.Size != null )
        this.Size = val.Size;
      if( !string.IsNullOrEmpty( this.Text ) )
        this.Text = val.Text;
      if( this.TextColor != null )
        this.TextColor = val.TextColor;
      if( this.DisabledColor != null )
        this.DisabledColor = val.DisabledColor;
      if( this.BackgroundTextureTint != null )
        this.BackgroundTextureTint = val.BackgroundTextureTint;
    }

    #endregion

    public string ScreenID {
      get {
        return this.GetElement( "ScreenID" ).InnerText;
      }
      set {
        this.Validate( "ScreenID" , value );
      }
    }
    public int Font {
      get {
        return int.Parse( this.GetElement( "Font" ).InnerText );
      }
      set {
        this.Validate( "Font" , value.ToString() );
      }
    }
    public bool RelativePosition {
      get {
        return bool.Parse( this.GetElement( "RelativePosition" ).InnerText );
      }
      set {
        this.Validate( "RelativePosition" , value.ToString() );
      }
    }
    public UIPoint Location {
      get {
        return ( UIPoint ) this.GetElement( "Location" );
      }
      set {
        this.Location.Validate( value , "Location" );
      }
    }
    public UISize Size {
      get {
        return ( UISize ) this.GetElement( "Size" );
      }
      set {
        this.Size.Validate( value , "Size" );
      }
    }
    public bool AutoStretch {
      get {
        return bool.Parse( this.GetElement( "AutoStretch" ).InnerText );
      }
      set {
        this.Validate( "AutoStretch" , value.ToString() );
      }
    }
    public bool AutoStretchVertical {
      get {
        return bool.Parse( this.GetElement( "AutoStretchVertical" ).InnerText );
      }
      set {
        this.Validate( "AutoStretchVertical" , value.ToString() );
      }
    }
    public bool AutoStretchHorizontal {
      get {
        return bool.Parse( this.GetElement( "AutoStretchHorizontal" ).InnerText );
      }
      set {
        this.Validate( "AutoStretchHorizontal" , value.ToString() );
      }
    }
    public bool TopAnchorToTop {
      get {
        return bool.Parse( this.GetElement( "TopAnchorToTop" ).InnerText );
      }
      set {
        this.Validate( "TopAnchorToTop" , value.ToString() );
      }
    }
    public bool LeftAnchorToLeft {
      get {
        return bool.Parse( this.GetElement( "LeftAnchorToLeft" ).InnerText );
      }
      set {
        this.Validate( "LeftAnchorToLeft" , value.ToString() );
      }
    }
    public bool BottomAnchorToTop {
      get {
        return bool.Parse( this.GetElement( "BottomAnchorToTop" ).InnerText );
      }
      set {
        this.Validate( "BottomAnchorToTop" , value.ToString() );
      }
    }
    public bool RightAnchorToLeft {
      get {
        return bool.Parse( this.GetElement( "RightAnchorToLeft" ).InnerText );
      }
      set {
        this.Validate( "RightAnchorToLeft" , value.ToString() );
      }
    }
    public int TopAnchorOffset {
      get {
        return int.Parse( this.GetElement( "TopAnchorOffset" ).InnerText );
      }
      set {
        this.Validate( "TopAnchorOffset" , value.ToString() );
      }
    }
    public int BottomAnchorOffset {
      get {
        return int.Parse( this.GetElement( "BottomAnchorOffset" ).InnerText );
      }
      set {
        this.Validate( "BottomAnchorOffset" , value.ToString() );
      }
    }
    public int LeftAnchorOffset {
      get {
        return int.Parse( this.GetElement( "LeftAnchorOffset" ).InnerText );
      }
      set {
        this.Validate( "LeftAnchorOffset" , value.ToString() );
      }
    }
    public int RightAnchorOffset {
      get {
        return int.Parse( this.GetElement( "RightAnchorOffset" ).InnerText );
      }
      set {
        this.Validate( "RightAnchorOffset" , value.ToString() );
      }
    }
    public int MinVSize {
      get {
        return int.Parse( this.GetElement( "MinVSize" ).InnerText );
      }
      set {
        this.Validate( "MinVSize" , value.ToString() );
      }
    }
    public int MinHSize {
      get {
        return int.Parse( this.GetElement( "MinHSize" ).InnerText );
      }
      set {
        this.Validate( "MinHSize" , value.ToString() );
      }
    }
    public int MaxVSize {
      get {
        return int.Parse( this.GetElement( "MaxVSize" ).InnerText );
      }
      set {
        this.Validate( "MaxVSize" , value.ToString() );
      }
    }
    public int MaxHSize {
      get {
        return int.Parse( this.GetElement( "MaxHSize" ).InnerText );
      }
      set {
        this.Validate( "MaxHSize" , value.ToString() );
      }
    }
    public string Text {
      get {
        return this.GetElement( "Text" ).InnerText;
      }
      set {
        this.Validate( "Text" , value );
      }
    }
    public RGB TextColor {
      get {
        return ( RGB ) this.GetElement( "TextColor" );
      }
      set {
        this.TextColor.Validate( value , "TextColor" );
      }
    }
    public RGB DisabledColor {
      get {
        return ( RGB ) this.GetElement( "DisabledColor" );
      }
      set {
        this.DisabledColor.Validate( value , "DisabledColor" );
      }
    }
    public bool UseInLayoutHorizontal {
      get {
        return bool.Parse( this.GetElement( "UseInLayoutHorizontal" ).InnerText );
      }
      set {
        this.Validate( "UseInLayoutHorizontal" , value.ToString() );
      }
    }
    public bool UseInLayoutVertical {
      get {
        return bool.Parse( this.GetElement( "UseInLayoutVertical" ).InnerText );
      }
      set {
        this.Validate( "UseInLayoutVertical" , value.ToString() );
      }
    }
    public RGB BackgroundTextureTint {
      get {
        return ( RGB ) this.GetElement( "BackgroundTextureTint" );
      }
      set {
        this.BackgroundTextureTint.Validate( value , "BackgroundTextureTint" );
      }
    }

  }
}
